package com.changanw.tonumplus;

public class ListNode {
    int val;
    ListNode next;
    public ListNode() {

    }
    public ListNode(int val) {
        this.val = val;
    }
    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public String showLinkedlist(ListNode listNod1, ListNode listNode2){
        String s = new String();
        ListNode head1 = listNod1;
        ListNode head2 = listNode2;
        ListNode listNode = new ListNode();
        ListNode head3 = listNode;
        //既然要输出，就要遍历，因此又要一个临时变量来遍历
        int a = 0;

        while(head1 !=null && head2 != null){
            int b = head1.val+head2.val +a ;
            int c;
            if ( b > 10){
               c = b%10;
               a = 1;
            }else {
                a=0;
                c=b;
            }
            head3.next = new ListNode(c);
            head1=head1.next;
            head2= head2.next;

        }
        return s;
    }
    public String listToString(ListNode listNode){
        StringBuffer s = new StringBuffer();
        ListNode temp = listNode;
        while (temp != null){
            s.append(temp.val);
            temp = temp.next;
        }
        return s.reverse().toString();
    }



}
